package com.kyd.push.mqservice;

import com.aliyun.openservices.ons.api.*;
import com.kyd.push.common.utils.IdWorker;
import com.kyd.push.model.OrderMqContext;
import com.kyd.push.model.TopicEnum;
import com.kyd.push.mq.ProduceRequest;
import lombok.extern.slf4j.Slf4j;

import java.util.Properties;

/**
 * ProducerTest
 *
 * @author kejw on 2018/9/27
 */

@Slf4j
public class ProducerOrder {


	public static void send(OrderMqContext context) {
		Properties properties = new Properties();
		properties.put(PropertyKeyConst.ProducerId, "PID_kyd_consignor");
		properties.put(PropertyKeyConst.AccessKey,"LTAIASBYEVqRq4Wb");
		properties.put(PropertyKeyConst.SecretKey, "x0x85HMvoxVYjHXuBNlkafD2ElnrGB");
		properties.setProperty(PropertyKeyConst.SendMsgTimeoutMillis, "3000");
		properties.put(PropertyKeyConst.ONSAddr, "http://onsaddr-internet.aliyun.com/rocketmq/nsaddr4client-internet");

		Producer producer = ONSFactory.createProducer(properties);
		producer.start();

		ProduceRequest<OrderMqContext> request = new ProduceRequest<>(TopicEnum.ORDER.value(), "TagA", context);
		Message msg = new Message(request.getTopic(), request.getTagA(), request.getBodyBytes());

		producer.send(msg);

		log.info("producer_send");
	}

}
